package com.project.xsf.service.impl;

import com.project.junM.entity.TMember;
import com.project.xsf.entity.ChatInfo;
import com.project.xsf.mapper.ChatInfoMapper;
import com.project.xsf.service.ChatInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Transactional
@Service
public class ChatInfoImpl implements ChatInfoService {
    @Autowired
    private ChatInfoMapper chatInfoMapper;
    @Override
    public List<ChatInfo> queryInfoByMemberId(HttpSession session, Integer sysUserId) {
        TMember member = (TMember) session.getAttribute("user");
//        System.out.println(member);
        List<ChatInfo> chatInfos = chatInfoMapper.queryInfoByMemberId(member.getId(), sysUserId);
        return chatInfos;
    }

    @Override
    public int insertSelective(String msg,Integer sysUserId,HttpSession session) {
        ChatInfo chatInfo = new ChatInfo();
        chatInfo.setInfo(msg);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh-mm-ss");
        chatInfo.setCreatetime(simpleDateFormat.format(new Date()));
        chatInfo.setDirection(0);
        TMember member = (TMember) session.getAttribute("user");
        chatInfo.setMemberId(member.getId());
        chatInfo.setSysUserId(sysUserId);
        chatInfo.setState(0);

        return chatInfoMapper.insertSelective(chatInfo);
    }
}
